using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace MKDS_Course_Editor
{
    public partial class StaffGhostTime : Form
    {
        byte[][] time = new byte[32][];
        string file;
        public StaffGhostTime(string f)
        {
            InitializeComponent();
            file = f;
        }

        private void StaffGhostTime_Load(object sender, EventArgs e)
        {
            EndianBinaryReader er = new EndianBinaryReader(File.OpenRead(file));
            er.ReadBytes(0x20);
            for (int i = 0; i < 32; i++)
            {
                time[i] = new byte[4];
                time[i] = er.ReadBytes(4);
            }
            comboBox1.SelectedIndex = 0;
            er.Close();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int ms = parselittle(BitConverter.ToString(time[comboBox1.SelectedIndex]).Replace("-", ""));
            numericUpDown1.Value = TimeSpan.FromMilliseconds((double)Convert.ToDecimal(ms * 1000)).Hours;
            numericUpDown2.Value = TimeSpan.FromMilliseconds((double)Convert.ToDecimal(ms * 1000)).Minutes;
            numericUpDown3.Value = TimeSpan.FromMilliseconds((double)Convert.ToDecimal(ms * 1000)).Seconds;
        }
        int parselittle(string input)
        {
            int test = 0;
            test = int.Parse(input.ToCharArray()[6].ToString() + input.ToCharArray()[7].ToString() + input.ToCharArray()[4].ToString() + input.ToCharArray()[5].ToString() + input.ToCharArray()[2].ToString() + input.ToCharArray()[3].ToString() + input.ToCharArray()[0].ToString() + input.ToCharArray()[1].ToString(), System.Globalization.NumberStyles.HexNumber);
            return test;
        }
    }
}
